package com.kede.pay.chain;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.kede.api.pojo.pay.PayCodeEnum;
import com.kede.pay.annotation.PayNotifyHandler;
import com.kede.pay.pojo.NotifyPOJO;
import lombok.extern.slf4j.Slf4j;

/**
 * 支付下线物资的回调处理类
 * @Author:Pr.li
 * @Date: create in 2023/10/28 16:12
 */
@Slf4j
@PayNotifyHandler("OFSHandlerNotify")
public class OFSHandlerNotifyImpl implements IHandlerNotify{
    @Override
    public boolean match(String tag) {
        return tag.toLowerCase().equals(PayCodeEnum.OFFLINESUPPLIE.getCode().toLowerCase());
    }

    @Override
    public void doHandler(NotifyPOJO notifyPOJO) {
        JSONObject jsonObject = JSONObject.parseObject(notifyPOJO.getAttach());
        Integer payLogId = jsonObject.getInteger("payLogId");
        String url =  jsonObject.getString("url");
        log.debug("OFSHandlerNotify回调的结果是=={}",notifyPOJO.toString());
        HttpResponse execute = HttpRequest.get(url + "?payLogId=" + payLogId).execute();
        log.debug("payLogId回调的结果是=={}",execute.toString());
    }
}
